package cn.tedu.calendar.controller;

import cn.tedu.base.response.JsonResult;
import cn.tedu.calendar.pojo.dto.CalendarParam;
import cn.tedu.calendar.pojo.dto.CalendarQuery;
import cn.tedu.calendar.pojo.vo.CalendarVO;
import cn.tedu.calendar.service.CalendarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/calendar")
@Slf4j
public class CalendarController {
    @Autowired
    private CalendarService calendarService;
    @GetMapping("select")
    public JsonResult selectByUserId(Long userId){
        log.debug("查询{}",userId);
        List<CalendarVO> calenderVos = calendarService.selectByUserId(userId);
        return JsonResult.ok(calenderVos);
    }

    @PostMapping("save")
    public JsonResult insertCalender(CalendarParam calendarParam){
        log.debug("需要保存的数据{}",calendarParam);
        calendarService.saveMemo(calendarParam);
        return JsonResult.ok();
    }

    @GetMapping("select/datas")
    public JsonResult selectByData(CalendarQuery calendarQuery){
        List<CalendarVO> calendarVos = calendarService.selectByDates(calendarQuery);
        return JsonResult.ok(calendarVos);
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteMemo(@PathVariable Long id){
        log.debug("删除的数据{}",id);
        calendarService.deleteMemo(id);
        return JsonResult.ok();
    }
}
